﻿using SiliconSelect.Base;
using SiliconSelect.BLL;
using SiliconSelect.Common;
using SiliconSelect.Views;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;

namespace SiliconSelect
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// 主程序的入口,先打开登录界面
        /// </summary>
        /// <param name="e"></param>
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);
            LogHelper.WriteLog(LogType.Info, "程序启动......");
            // 首先是创建所有的数据表
            DataResult tableInit = TableManager.CreateTotalTables();
            if (!tableInit.State)
            {
                MessageBox.Show(tableInit.Message);
                LogHelper.WriteLog(LogType.Fatal, tableInit.Message + "程序退出!");
                Current.Shutdown();
                return;
            }
            ProcessManager.KillProcessByPort(GlobalValues.PcAddrList);
            Task task = Task.Factory.StartNew(async () =>
            {
                await Task.Delay(1000);
            });
            // 先弹出登录窗口
            //if (new LoginView().ShowDialog() == true)
            //{
            //    new MainView().ShowDialog();
            //}

            // 调试的时候直接弹出主窗口
            new MainView().ShowDialog();

            Current.Shutdown();
        }
    }
}
